import { useReducer } from "react";
const getDefaultCity=()=>{
    let defaultCity="武汉";
    if(localStorage.getItem("city")){
        defaultCity = localStorage.getItem("city")
    }
    return defaultCity
}
const useCityReducer=()=>{
    const initState={
        city:getDefaultCity()
    }
    const reducer=(state,action)=>{
        if(action.type=="handleCity"){
            localStorage.setItem("city",action.value)
            return{
                city:action.value
            }
        }
        return initState;
    }
    const [state,dispatch] = useReducer(reducer,initState)
    return [state,dispatch]
}
export default useCityReducer;